package com.zd.commodity.userMng.dao.impl;

import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

import com.zd.commodity.dao.impl.BaseDao;
import com.zd.commodity.userMng.dao.IMmenuDao;
import com.zd.commodity.userMng.entity.Mmenu;

public class MmenuDao extends BaseDao<Mmenu> implements IMmenuDao{

	
	@Override
	public DetachedCriteria getDetachedCriteria(Mmenu mmenu1, Mmenu mmenu2, Object param) {
		// 构建查询条件
		DetachedCriteria dc=DetachedCriteria.forClass(Mmenu.class);
		if(mmenu1!=null)
		{
			if(mmenu1.getText()!=null &&  mmenu1.getText().trim().length()>0)
			{
				dc.add(Restrictions.like("text", mmenu1.getText(), MatchMode.ANYWHERE));			
			}
		}
		
		
		if(param!=null && !param.equals("") && Integer.parseInt((String)param)==0){
			//zhu
			dc.add(Restrictions.eq("parentId", (long)0));
			ServletActionContext.getRequest().setAttribute("menus", "mainMenus");
		}
		if(param!=null && !param.equals("") && Integer.parseInt((String)param)==1){
			//zi
			dc.add(Restrictions.gt("parentId", (long)0));
			ServletActionContext.getRequest().setAttribute("menus", "subMenus");
		}
		
		return dc;
	}

	@Override
	public void getUserMenu(String uid) {
		getHibernateTemplate().find("from Mmenu ");
		
	}

}
